/*
 * TickTacToeComponent.fx
 *
 * Created on Apr 27, 2009, 5:03:11 AM
 */

package com.dg.gaming.tictactoe.client.fx;

import com.dg.gaming.tictactoe.common.TicTacToeModel;
import java.lang.Object;
import java.util.Observable;
import java.util.Observer;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
 * @author dito
 */

public class TickTacToeComponent extends Rectangle, Observer{
    
   public  var model:TicTacToeModel ;
   public  var X1:Integer;
   public  var Y1:Integer;
   
   init{
       model.addObserver(this);
       refresh();
       
   }
   function getColor(x:Integer, y:Integer):Color{
        var piece = model.getData(x, y);

                 if (piece != TicTacToeModel.BLANK) {
                    if(piece==TicTacToeModel.O)
                    return Color.BLUE
                    else
                    return Color.YELLOW;
                 }

        return Color.WHITE;
    }
   function refresh(){
       fill=getColor(X1, Y1);
   }



   public override function update(arg0:Observable , arg1:Object ) {
        refresh();
   }

}
